#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e5 + 10;

struct Record{
    string name,id;
    char gender;
    int grade;        
}stu[N];

int n;

bool cmp(const Record & r1, const Record & r2) {
    if (r1.gender == r2.gender) {
        if (r1.gender == 'F') 
            return r1.grade > r2.grade;
        else
            return r1.grade < r2.grade;
    }
    return r1.gender < r2.gender;
}

inline void solution() {
    cin >> n;
    for (int i = 0; i < n; i ++ ) 
        cin >> stu[i].name >> stu[i].gender >> stu[i].id >> stu[i].grade;

    sort(stu, stu + n, cmp);
    int gf = -INF, gm = INF;
    pair<string, string> f, m;

    for (int i = 0; i < n; i ++ ) {
        if (stu[i].gender == 'F') {
            if (gf < stu[i].grade)
                f = mk(stu[i].name, stu[i].id);
            gf = max(gf, stu[i].grade);
        } else {
            if (gm > stu[i].grade) 
                m = mk(stu[i].name, stu[i].id);
            gm = min(gm, stu[i].grade);
        }
    }
    if (gf == -INF) cout << "Absent" << endl;
    else cout << f.first << " " << f.second << endl;
    if (gm == INF) cout << "Absent" << endl;
    else cout << m.first << " " << m.second << endl;
    if (gm == INF || gf == -INF) cout << "NA" << endl;
    else cout << gf - gm << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}